package com.finalx.TrafficBytes;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MyDbHelper extends SQLiteOpenHelper{
	private String TAG = "TrafficBytes:@@MyDbHelper";

	public static final String DATABASE_NAME = "TrafficBytes.db";
	public static final String TABLE_NAME = "everyday_usage";
	public static final String COLUMN_DATE = "date";
	public static final String COLUMN_TX = "tx";
	public static final String COLUMN_RX = "rx";
	public static final String COLUMN_TYPE = "type";
	
	public static final int COLUMN_TYPE_MOBILE = 0;
	public static final int COLUMN_TYPE_WIFI = 1;

	public MyDbHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
		Log.d(TAG, "New instance created");
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ("
				+ COLUMN_DATE + " INTEGER, " 
				+ COLUMN_TX + " LONG," + COLUMN_RX + " LONG, "
				+ COLUMN_TYPE + " INTEGER, UNIQUE(" + COLUMN_DATE + ", " + COLUMN_TYPE + ")"
				+ ");");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		//simplely drop old version of table current now
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(db);
	}

}
